package com.itheima.utils;

import com.itheima.pojo.SysUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PasswordToEncodeUtils implements UserDetailsService {
    //创建加密工具类
    private static PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    //给密码加密
    public static Boolean PasswordToEncode(SysUser sysUser) {
        //1.获取添加的密码
        String password = sysUser.getPassword();
        //2.修改数据库中的密码
        String encodePassword = passwordEncoder.encode(password);
        sysUser.setPassword(encodePassword);
        //3.校验  解密，加密的密码是否是填写的密码
        boolean flag = passwordEncoder.matches(password, encodePassword);
        return flag;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return null;
    }
}
